////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef __WN_THREAD_JOB_H__
#define __WN_THREAD_JOB_H__

#include "WNCore/inc/WNTypes.h"
#include "WNContainers/inc/WNResourceBase.h"
#include "WNConcurrency/inc/WNThread.h"

namespace WNConcurrency {
    class WNThreadJob : public WNContainers::WNResourceBase {
    public:
        WNThreadJob() :
            mCompleted(WN_FALSE) {
        }
        virtual ~WNThreadJob() {
            
        }
        virtual WN_VOID Execute() = 0;
        WN_VOID WaitForCompletion() {
            while(!mCompleted) {
                WNConcurrency::WNThreadYield();
            }
        }
        WN_BOOL Completed() {
            return(mCompleted);
        }
    private:
        friend class WNThreadPool;
        volatile WN_BOOL mCompleted;
    };
}

#endif//__WN_THREAD_JOB_H__